package com.kgc.airquality.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kgc.airquality.mapper.AirqualityindexMapper;
import com.kgc.airquality.pojo.Airqualityindex;
import com.kgc.airquality.pojo.AirqualityindexExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class airqualityindexServiceImpl implements  airqualityindexService{
    @Resource
    AirqualityindexMapper airqualityindexMapper;
    @Override
    public PageInfo<Airqualityindex> sele(Integer pageNum, Integer districtId) {
        PageHelper.startPage(pageNum,2);
        List<Airqualityindex> airqualityindices;
        if (districtId!=0){
            AirqualityindexExample example=new AirqualityindexExample();
            AirqualityindexExample.Criteria criteria = example.createCriteria();
            criteria.andIdEqualTo(districtId);
          airqualityindices = airqualityindexMapper.selectByExample(example);
        }else {
           airqualityindices = airqualityindexMapper.selectByExample(null);
        }
        PageInfo<Airqualityindex> pageInfo=new PageInfo<>(airqualityindices);
        return pageInfo;
    }

    @Override
    public Integer delete(Integer id) {
        int i=airqualityindexMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public Integer add(Airqualityindex airqualityindex) {
        int i=airqualityindexMapper.insert(airqualityindex);
        return i;
    }

    @Override
    public Airqualityindex selectByid(Integer id) {
        Airqualityindex airqualityindex=airqualityindexMapper.selectByPrimaryKey(id);
        return airqualityindex;
    }

    @Override
    public Integer update(Airqualityindex airqualityindex) {
int i=airqualityindexMapper.updateByPrimaryKeySelective(airqualityindex);
        return i;
    }
}
